package hnevc.com.netfoodchoosez;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashActivity extends AppCompatActivity {

    //定义handler消息处理者
    Handler mHandler = new Handler(){

        public void handleMessage(Message msg){
            if(msg.what==101){
                //如果是101信号，则跳转
                //创建显示意图
                Intent intent = new Intent();
                intent.setClass(SplashActivity.this,
                        MainActivity.class);
                //根据intent，启动Activity
                startActivity(intent);
                //关闭当前activity
                SplashActivity.this.finish();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        //获取图片控件
        ImageView imageView = (ImageView)findViewById(R.id.id_iv_splash);
        //获取补间动画
        Animation animation = AnimationUtils.loadAnimation(this,R.anim.scale_animation);
        //应用不见动画
        imageView.startAnimation(animation);



        new Thread( new Runnable(){
             public void run(){
                 int i=0;
                 while(true){
                     try{
                         Thread.sleep(1000);
                         i++;
                     }catch(InterruptedException e){
                         e.printStackTrace();
                     }
                     if(i==4){
                         Message msg = new Message();
                         msg.what=101;
                         mHandler.sendMessage(msg);
                     }
                 }
             }

        }).start();
    }
}
